package com.zbf.chongshi;

import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author: LCG
 * @Date: 2021-10-21 12:04:08
 * @description: 测试Spring提供的retry机制
 **/
@Component
public class TestChongshi {

    @Retryable(value = {RuntimeException.class},maxAttempts = 3,backoff =@Backoff(delay = 2000,multiplier = 2),listeners = {"myRetryListener"})
    public void testRetry(Map<String,String> map){

        System.out.println("000000000000000000000000000000000000");

        if(map.isEmpty()){
            throw new RuntimeException("==========9999==========");
        }

    }


    /** 
     * @author: LCG
     * @date: 2021/10/21
     * @description:  该方法用来做兜底，如果对目标方法的所有尝试调用都失败的时候会执行这个方法，做最后的兜底处理
     */
    @Recover
    public void testRetry02(RuntimeException runtimeException){
        System.out.println("======兜底回调====");
    }

}
